package work;

import entity.text.ChapterEntity;
import entity.text.PaperEntity;
import front.CitationFront;
import util.TextRankKeyword;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author ：hzs
 * @date ：Created in 2021/2/14 16:45
 * @description：
 * @modified By：
 * @version: $
 */
public class Work1 {

    /**
     * 使用textrank算法提取每一段的关键词，取前五
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception{
        String id1 = "1658";
        String id2 = "";
        CitationFront citationFront = new CitationFront();
        PaperEntity paperEntity = citationFront.readPaperById(id1);
//        String fullTextFromPaperEntity = PaperEntityUtil.getFullTextFromPaperEntity(citationFront.readPaperById("1330"));
//        String fullTextFromPaperEntity1 = PaperEntityUtil.getFullTextFromPaperEntity(citationFront.readPaperById("2690"));
//        System.out.println(JaccardTextSimilarity.getSimilarity(fullTextFromPaperEntity1, fullTextFromPaperEntity));
        List<ChapterEntity> chapterEntities = paperEntity.getChapterEntities();
        int i = 1;
        while (true) {
            String title = "";
            String content = "";
            for (ChapterEntity chapterEntity : chapterEntities) {
                String index = chapterEntity.getIndex();
                if (String.valueOf(i).equals(index)) {
                    title = chapterEntity.getSubTitle();
                }
                if (index.equals(String.valueOf(i))
                        || index.startsWith(String.valueOf(i).concat("."))) {
                    content = content.concat(" ").concat(chapterEntity.getContent());
                }
            }
            if ("".equals(content)) {
                break;
            } else {
                Map<String, Float> keywords = TextRankKeyword.getKeyword(title, content);
                List<Map.Entry<String, Float>> entryList = new ArrayList<>(keywords.entrySet());
                Collections.sort(entryList, (a, b) -> a.getValue() - b.getValue() > 0 ? -1 : 1);
                i++;
            }
        }
    }

}
